import request from '@/utils/request'
import type { LoginRequest, LoginResponse, User } from '@/types'

/**
 * 认证相关API接口
 */
export const authApi = {
  /**
   * 用户登录
   * @param credentials 登录凭据
   */
  login: (credentials: LoginRequest) => 
    request.post<LoginResponse>('/auth/login', credentials),
  
  /**
   * 用户注册
   * @param userData 用户注册数据
   */
  register: (userData: {
    username: string
    password: string
    email: string
    fullName: string
    phone?: string
  }) => request.post<User>('/auth/register', userData),
  
  /**
   * 用户登出
   */
  logout: () => 
    request.post('/auth/logout'),
  
  /**
   * 获取当前用户信息
   */
  getCurrentUser: () => 
    request.get<User>('/auth/me'),
  
  /**
   * 刷新访问令牌
   */
  refreshToken: () => 
    request.post<{ token: string }>('/auth/refresh'),
  
  /**
   * 修改密码
   * @param data 密码修改数据
   */
  changePassword: (data: {
    oldPassword: string
    newPassword: string
    confirmPassword: string
  }) => request.put('/auth/change-password', data),
  
  /**
   * 忘记密码 - 发送重置邮件
   * @param email 邮箱地址
   */
  forgotPassword: (email: string) => 
    request.post('/auth/forgot-password', { email }),
  
  /**
   * 重置密码
   * @param data 重置密码数据
   */
  resetPassword: (data: {
    token: string
    newPassword: string
    confirmPassword: string
  }) => request.post('/auth/reset-password', data)
}

